<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      /*methods: {
        initChart() {
          this.chart = echarts.init(this.$el, 'macarons');

          this.updateData(); // 初始加载时先调用一次

          // 设置定时器，每10分钟（600000毫秒）更新一次数据
          this.dataUpdateInterval = setInterval(() => {
            this.updateData();
          }, 600000);
        },

        updateData() {
          // 假设从 API 获取新数据，实际应用中应替换为合适的接口调用
          const newData = [
            { value: /!* 更新值 *!/, name: '行业' },
            { value: /!* 更新值 *!/, name: '技术' },
            { value: /!* 更新值 *!/, name: '外汇' },
            { value: /!* 更新值 *!/, name: '黄金' },
            { value: /!* 更新值 *!/, name: '预测' }
          ];

          // 更新图表数据并刷新视图
          this.chart.setOption({
            series: [
              {
                data: newData
              }
            ]
          });*/


      this.chart.setOption({
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          left: 'center',
          bottom: '10',
          data: ['技术总监', '明星设计师', '正式店长', '中级设计师', '预备设计师']
        },
        series: [
          {
            name: '每周不同级别员工获取订单量',
            type: 'pie',
            roseType: 'radius',
            radius: [15, 95],
            center: ['50%', '38%'],
            data: [
              { value: 320, name: '技术总监' },
              { value: 240, name: '明星设计师' },
              { value: 149, name: '正式店长' },
              { value: 100, name: '中级设计师' },
              { value: 59, name: '预备设计师' }
            ],
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
        ]
      })
    }
  }
}
</script>
